package nexus.com.list
{
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import nexus.base.NXSprite;
	
	public class ListItem extends NXSprite
	{
		//-----------------------------------------------------------------------------------
		//
		// private vars
		//
		//-----------------------------------------------------------------------------------
		
		private var _overBg : Shape;
		private var _labelTF : TextField;
		private var _data : Object;
		private var _label : String = "";
		
		private var _overBgColor : uint = 0xc50102;
		private var _overTextColor : uint = 0xffffff;
		private var _defaultTextForamt : TextFormat;
		private var _overTextFormat : TextFormat;
		
		
		//-----------------------------------------------------------------------------------
		//
		// protected vars
		//
		//-----------------------------------------------------------------------------------
		
		
		//-----------------------------------------------------------------------------------
		//
		// public vars
		//
		//-----------------------------------------------------------------------------------
		
		
		//-----------------------------------------------------------------------------------
		//
		// constructor
		//
		//-----------------------------------------------------------------------------------
		public function ListItem()
		{
			super();
			
			viewWidth = 200;
			viewHeight = 20;
			
			_overBg = new Shape();
			var g : Graphics = _overBg.graphics;
			g.beginFill( _overBgColor, 1 );
			g.drawRect( 0,0, viewWidth,viewHeight );
			g.endFill();
			_overBg.alpha = 0;
			addChild( _overBg );
			
			_defaultTextForamt = new TextFormat( "돋움", 12, 0x898989, false );
//			_defaultTextForamt.leading = 4;
			overTextColor = _overTextColor;
			
			_labelTF = new TextField();
			_labelTF.width = viewWidth;
			_labelTF.height = _labelTF.textHeight + 4;
			_labelTF.mouseEnabled = false;
			_labelTF.mouseWheelEnabled = false;
			_labelTF.setTextFormat( _defaultTextForamt );
			_labelTF.defaultTextFormat = _defaultTextForamt;
			
			_labelTF.y = ( viewHeight - _labelTF.height )/2; 
			
			addChild( _labelTF );
			
		}
		
		//-----------------------------------------------------------------------------------
		//
		// setter / getter
		//
		//-----------------------------------------------------------------------------------

		override public function set viewWidth(value:Number):void
		{
			super.viewWidth = value;
			if(_overBg != null)	_overBg.width = viewWidth;
			if(_labelTF != null) _labelTF.width = viewWidth;
		}

		override public function set viewHeight(value:Number):void
		{
			super.viewHeight = value;
			if(_overBg != null) _overBg.height = viewHeight;
		}
		
		public function get label():String
		{
			return _label;
		}

		public function set label(value:String):void
		{
			_label = value;
			this._labelTF.text = ( _label ) ? _label : "";
			_labelTF.height = _labelTF.textHeight + 4;
			_labelTF.y = ( viewHeight - _labelTF.height )/2;
			if( _labelTF != null ){ 
				this._labelTF.text = ( _label ) ? _label : "";
				_labelTF.height = _labelTF.textHeight + 4;
				_labelTF.y = ( viewHeight - _labelTF.height )/2;
			}
		}

		public function get defaultTextForamt():TextFormat
		{
			return _defaultTextForamt;
		}

		public function set defaultTextForamt(value:TextFormat):void
		{
			_defaultTextForamt = value;
			this._labelTF.setTextFormat( _defaultTextForamt );
			this._labelTF.defaultTextFormat = _defaultTextForamt;
		}

		public function get overTextColor():uint
		{
			return _overTextColor;
		}

		public function set overTextColor(value:uint):void
		{
			_overTextColor = value;
			
			this._overTextFormat = new TextFormat();
			this._overTextFormat.font = _defaultTextForamt.font;
			this._overTextFormat.color = _overTextColor;
			this._overTextFormat.size = _defaultTextForamt.size;
			this._overTextFormat.bold = _defaultTextForamt.bold;
			this._overTextFormat.leading = _defaultTextForamt.leading;
		}

		public function get overBgColor():uint
		{
			return _overBgColor;
		}

		public function set overBgColor(value:uint):void
		{
			_overBgColor = value;
			
			var g : Graphics = _overBg.graphics;
			g.clear();
			g.beginFill( _overBgColor, 1 );
			g.drawRect( 0,0, viewWidth,viewHeight );
			g.endFill();
		}


		public function set data( __data : Object ):void
		{
			this._data = __data;
		}
		
		public function get data():Object
		{
			return _data;
		}
		
		//-----------------------------------------------------------------------------------
		//
		// public function
		//
		//-----------------------------------------------------------------------------------
		
		override public function updateDisplayList():void
		{
			super.updateDisplayList();
			
			_overBg.width = viewWidth;
			_overBg.height = viewHeight
		}
		
		
		public function ON():ListItem
		{
			_labelTF.setTextFormat( _overTextFormat );
			_overBg.alpha = 1;
			
			return this;
		}
		
		
		public function OFF():ListItem
		{
			_labelTF.setTextFormat( _defaultTextForamt );
			_overBg.alpha = 0;
			
			return this;
		}
		
		//-----------------------------------------------------------------------------------
		//
		// protected function
		//
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// private function
		//
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// event handler
		//
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// destory
		//
		//-----------------------------------------------------------------------------------
		override public function destory():void
		{
			super.destory();
		}
		
		
	}
}